package tr.gov.tubitak.bilgem.esya.certselector;/*
 * Created by JFormDesigner on Wed Mar 21 13:33:46 EET 2012
 */

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
 * @author Haydar Karabas
 */
public class EReaderCertTreePanel extends JPanel {
    EReaderCertTreeManager readerCertTreeManager;

    public void setShowOnlyQualifiedCerts(boolean showOnlyQualifiedCerts) {
        this.showOnlyQualifiedCerts = showOnlyQualifiedCerts;
        readerCertTreeManager.setShowOnlyQualifiedCerts(showOnlyQualifiedCerts);
    }

    boolean showOnlyQualifiedCerts=false;

    public ReaderCertListTree getReaderCertListTree() {
        return readerCertListTree;
    }

    public EReaderCertTreePanel(){
        initComponents();
        this.showOnlyQualifiedCerts=false;
        initGUI();
    }
    public EReaderCertTreePanel(boolean showOnlyQualifiedCerts) {
        initComponents();
        this.showOnlyQualifiedCerts=showOnlyQualifiedCerts;
        readerCertTreeManager.setShowOnlyQualifiedCerts(showOnlyQualifiedCerts);
        initGUI();
    }

    void initGUI()
    {
        readerCertTreeManager = new EReaderCertTreeManager(readerCertListTree,showOnlyQualifiedCerts);
        readerCertListTree.setCellRenderer(new ReaderCertListTreeRenderer());
    }


    public void loadTree()
    {
        readerCertTreeManager.setShowOnlyQualifiedCerts(showOnlyQualifiedCerts);
        readerCertTreeManager.loadTree();
    }

    private void btnRefreshActionPerformed(ActionEvent e) {
        loadTree();
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        scrollPane1 = new JScrollPane();
        xPnlCertTree = new JPanel();
        readerCertListTree = new ReaderCertListTree();
        panelCertTree = new JPanel();
        btnRefresh = new JButton();

        //======== this ========
        setLayout(new GridBagLayout());
        ((GridBagLayout)getLayout()).columnWidths = new int[] {0, 0};
        ((GridBagLayout)getLayout()).rowHeights = new int[] {0, 0};
        ((GridBagLayout)getLayout()).columnWeights = new double[] {1.0, 1.0E-4};
        ((GridBagLayout)getLayout()).rowWeights = new double[] {1.0, 1.0E-4};

        //======== scrollPane1 ========
        {
            scrollPane1.setBorder(null);

            //======== xPnlCertTree ========
            {
                xPnlCertTree.setLayout(new GridBagLayout());
                ((GridBagLayout)xPnlCertTree.getLayout()).columnWidths = new int[] {0, 0, 0};
                ((GridBagLayout)xPnlCertTree.getLayout()).rowHeights = new int[] {0, 0};
                ((GridBagLayout)xPnlCertTree.getLayout()).columnWeights = new double[] {1.0, 0.0, 1.0E-4};
                ((GridBagLayout)xPnlCertTree.getLayout()).rowWeights = new double[] {1.0, 1.0E-4};
                xPnlCertTree.add(readerCertListTree, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
                    GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                    new Insets(0, 0, 0, 0), 0, 0));

                //======== panelCertTree ========
                {
                    panelCertTree.setBackground(UIManager.getColor("Tree.background"));
                    panelCertTree.setLayout(new BorderLayout());

                    //---- btnRefresh ----
                    btnRefresh.setIcon(new ImageIcon(getClass().getResource("/tr/gov/tubitak/bilgem/esya/certselector/images/MIM_Refresh_16.png")));
                    btnRefresh.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            btnRefreshActionPerformed(e);
                        }
                    });
                    panelCertTree.add(btnRefresh, BorderLayout.PAGE_END);
                }
                xPnlCertTree.add(panelCertTree, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
                    GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                    new Insets(0, 0, 0, 0), 0, 0));
            }
            scrollPane1.setViewportView(xPnlCertTree);
        }
        add(scrollPane1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0), 0, 0));
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JScrollPane scrollPane1;
    private JPanel xPnlCertTree;
    private ReaderCertListTree readerCertListTree;
    private JPanel panelCertTree;
    private JButton btnRefresh;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
